package courseInfo;


import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/*

输入文件为学生成绩信息，包含了必修课与选修课成绩，
格式如下:
班级1，姓名1，科目1，必修，成绩1
班级2，姓名2，科目1，必修，成绩2
班级1，姓名1，科目2，选修，成绩3

实现功能：计算每个学生必修课的平均成绩

*/
public class CourseInfoMapper extends Mapper<LongWritable, Text, Text, DoubleWritable>{
    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{
        String line = value.toString();
        String str[] = line.split(",");
        if(str[3].equals("必修")){
            context.write(new Text(str[0] + "," + str[1]), new DoubleWritable(Double.valueOf(str[4])));
        }
    }
}
